#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    long long maximumHappinessSum(vector<int>& happiness, int k) {
        sort(happiness.begin(), happiness.end(), greater<int>());
        long long ret = 0;
        for (int i = 0; i < k; ++i)
        {
            int tmp = happiness[i] - i;
            if (tmp > 0) ret += tmp;
            else    break;
        }

        return ret;
    }
};